package ija.controller;

import ija.controller.CheckersController.Confirm;
import ija.controller.types.GameState;
import ija.model.CheckersModel;
import ija.model.GameModel;
import ija.model.players.ComputerPlayer;
import ija.model.players.Player;
import ija.model.types.FigureColor;
import ija.view.GameContent;
import ija.view.elements.PlayerPanel;
import ija.view.elements.PlayerPanel.PlayerChangeListener;
import ija.xls.notation.GameMove;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class GameController {

    protected MainController mainController;
    protected GameState state;
    protected GameContent view;
    protected GameModel model;

    public GameController(MainController mc) {
        this.mainController = mc;
        this.setState(GameState.GAMESETTINGS);
    }

    public void setState(GameState gs) {
        this.state = gs;
    }

    public GameState getState() {
        return this.state;
    }

    public void setView(GameContent gc) {
        this.view = gc;
    }

    public GameContent getView() {
        return this.view;
    }

    public GameModel getModel() {
        return this.model;
    }

    public void setModel(GameModel gm) {
        this.model = gm;
    }

    public MainController getMainController() {
        return this.mainController;
    }

    public void setMainController(MainController mc) {
        this.mainController = mc;
    }

    public void initModel(FigureColor TopFc) {
        this.model = new CheckersModel();
    }

    public void ConnectWithPlayer(Player player) {

    }

    public void TurnRound() {

    }

    public GameMove PlayAI(Player player) {
        return ((ComputerPlayer) player).calculateMove();
    }

    public List<String> GetAllMoves(FigureColor color) {
        // boolean jumpsonly = false;
        List<String> MoveList = new ArrayList<>();
        /*
         * for (Figure fig: Model.getDesk().getAllFigures(color)){ jumpsonly =
         * fig.getMoves(MoveList, jumpsonly) || jumpsonly; }
         */
        return MoveList;
    }

    public boolean Verify(FigureColor color, String moveNotation) {
        /*
         * for (String movable: GetAllMoves(color)){ if (movable ==
         * moveNotation) return true; }
         */
        return false;
    }

    public class StartGame implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (GameController.this.state == GameState.GAMESETTINGS) {
                GameController.this.setState(GameState.GAMEINPROGRESS);
                GameController.this.getView().setState(GameState.GAMEINPROGRESS);
            }
        }
    }

    public StartGame createStartGameListener() {
        return new StartGame();
    }

    public class SetPlayer implements PlayerChangeListener {
        @Override
        public void onPlayerChanged(PlayerPanel pp, Player p, int id) {
            // TODO Auto-generated method stub

        }
    }

    public SetPlayer createSetPlayerListener() {
        return new SetPlayer();
    }

    public class GiveUp implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
        }
    }

    public GiveUp createGiveUpListener() {
        return new GiveUp();
    }

    public class SaveGame implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    public SaveGame createSaveGameListener() {
        return new SaveGame();
    }

    public class MainMenu implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
        }
    }

    public MainMenu createMainMenuListener() {
        return new MainMenu();
    }

    public class LoadGame implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
        }
    }

    public LoadGame createLoadGameListener() {
        return new LoadGame();
    }

    public class ExitGame implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
        }
    }

    public ExitGame createExitGameListener() {
        return new ExitGame();
    }

    public class Move implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent event) {
        }
    }

    public Move createMoveListener() {
        return new Move();
    }

    public Confirm createConfirmListener() {
        // TODO Auto-generated method stub
        return null;
    }
};
